var gulp = require('gulp'), 
    less = require('gulp-less'),
	htmlmin = require('gulp-htmlmin'),
	inject = require('gulp-inject'),
	wiredep = require('wiredep').stream;
	gulpSequence = require('gulp-sequence');
 
gulp.task('less', function () {
    gulp.src('src/less/*.less') 
        .pipe(less()) 
        .pipe(gulp.dest('src/css')); 
});

gulp.task('htmlmin', function () {
    var options = {
        removeComments: true,
        collapseWhitespace: true,
        collapseBooleanAttributes: true,
        removeEmptyAttributes: true,
        removeScriptTypeAttributes: true,
        removeStyleLinkTypeAttributes: true,
        minifyJS: true,
        minifyCSS: true
    };
    gulp.src('src/html/*.html')
        .pipe(htmlmin(options))
        .pipe(gulp.dest('dist/html'));
}); 

gulp.task('inject', function () {
  var target = gulp.src('src/html/*.html');
  var sources = gulp.src(['./src/**/*.js', './src/**/*.css'], {read: false});

  return target.pipe(wiredep({
            devDependencies: true
        }))
	.pipe(inject(sources,{relative: true}))
    .pipe(gulp.dest('src/html'));
});


gulp.task('default', gulpSequence(['less', 'inject'],'htmlmin'));   
 